package CodingTest;

import java.util.Arrays;

public class QuickSort {
    private static int MAXNUM = 10;
    public static  void main(String[] args){
        int[] array = new int[MAXNUM];
        for(int i = 0;i < MAXNUM;i++){
            array[i] = (int)(100*Math.random()+1);
        }
        System.out.println("Original array:");//打印排序前的数组
        System.out.println(Arrays.toString(array));
        System.out.println("QuickSort");
        quickSort(array,0,array.length-1);
        System.out.println(Arrays.toString(array));

    }
    public static void quickSort(int[] array,int left,int right){
        if(left < right){
            int pivot = array[left];
            int low = left;
            int high = right;
            while(low < high){
                while(low < high && array[high] >= pivot)
                    high--;
                array[low] = array[high];
                while(low < high && array[low] <= pivot)
                    low++;
                array[high] = array[low];
            }
            array[low] = pivot;
            System.out.println("pivot = "+pivot + ","+Arrays.toString(array));
            quickSort(array,left,high-1);
            quickSort(array,low+1,right);

        }
    }
}
